﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using Infrastructure.ObjectModel;
using Infrastructure.Managers;
using Infrastructure.ServiceInterfaces;
using B10_Ex02_Elad_034695114_Meyron_026607788.ObjectModel;
using B10_Ex02_EladLebovitch_034695114.ObjectModel;

namespace B10_Ex02_Elad_034695114_Meyron_026607788
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Invadors : Microsoft.Xna.Framework.Game
    {
        #region Data Members

        private GraphicsDeviceManager m_Graphics;
        private SpriteBatch m_SpriteBatch;
        
        #region 2D Textures

        #endregion 

        private Vector2 m_VectorBG = Vector2.Zero;

        #endregion

        /// <summary>
        /// Classes Ctor
        /// </summary>
        public Invadors()
        {
            // Create the basic objects, set basic settings:
            m_Graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // Create the input and sprite batch
            InputManager inpManager = new InputManager(this);
            m_SpriteBatch = new SpriteBatch(GraphicsDevice);
            this.Services.AddService(typeof(SpriteBatch), m_SpriteBatch);

            // Create Collision detector
            CollisionDetector colManager = new CollisionDetector(this);
            
            // Set the background
            InvadorBackground ibgCurr = new InvadorBackground(this, @"Sprites\BG_Space01_1024x768");

            // Hand over init control to the game manager
            GameManager gmManager = new GameManager(this);
            base.Initialize();
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if ((this.Services.GetService(typeof(GameManager)) as GameManager).IsGameOver)
            {
                this.Exit();
            }

            // No logic yet
            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            // Clear everything
            GraphicsDevice.Clear(Color.Gold);

            // Draw basic status
            m_SpriteBatch.Begin();
            
            base.Draw(gameTime);

            // End draw
            m_SpriteBatch.End();
        }
    }
}
